#include <QPushButton> 

#include <QString>  

#include "materialdlg.h"


#include <QGraphicsScene>
#include <QGraphicsPixmapItem>

////////////////////////////////////////////////////////////
materialDlg::materialDlg(QWidget *parent)
	: QDialog(parent) 
{
	
   setupUi(this);
   connect( closeButton, SIGNAL( clicked() ), this, SLOT( sair() ) );
   connect( clearButton, SIGNAL( clicked() ), this, SLOT( limpar() ) );
   connect( applyButton, SIGNAL( clicked() ), this, SLOT( salvar () ) );


   connect(linearButton, SIGNAL(toggled(bool)), this, SLOT(trocarMaterial()));
   connect(bilinearButton, SIGNAL(toggled(bool)), this, SLOT(trocarMaterial()));

		
   //image.load(":/acmFrame/images/dialogos/restricao.png"); 

   image.load(":/acmFrame/images/dialogos/linear_lk.png"); 
   this->graphicsView->setScene(new QGraphicsScene());
   this->graphicsView->scene()->addItem(new QGraphicsPixmapItem(image));

}


///////////////////////////////////////////////////////////
materialDlg::~materialDlg()
{

}


///////////////////////////////////////////////////////////
void materialDlg::sair()
{
	this->close(); 
}

///////////////////////////////////////////////////////////
void materialDlg::limpar()
{
	this->linearModElast->setText("0.00");
	this->linearPoisson->setText("0.00");
	this->biModElast->setText("0.00");
	this->biPoisson->setText("0.00");
	this->biEscoamento->setText("0.00");
	this->biEncruamento->setText("0.00");

}


//////////////////////////////////////////////////////////////
void materialDlg::salvar()
{
   	*linearModElast_d=(float)this->getLinearModElast();
	*linearPoisson_d=(float)this->getLinearPoisson();
	*biModElast_d=(float)this->getBiModElast();
	*biPoisson_d=(float)this->getBiPoisson();
	*biEscoamento_d=(float)this->getBiEscoamento();
	*biEncruamento_d=(float)this->getBiEncruamento();

	
	this->close(); 

}

//////////////////////////////////////////////////////////////

void materialDlg::setMaterialTipo(MaterialTipo *materialTipo) 
{	
	this->materialTipo=materialTipo;

	linearGroupBox->setEnabled(false);    //material linear 
	bilinearGroupBox->setEnabled(false);    //material bilinear

	switch (*materialTipo)
	{
	case LINEAR_ELASTIC:
		this->linearButton->setChecked(true);
		linearGroupBox->setEnabled(true); 
		break;
	case BI_LINEAR:
		this->bilinearButton->setChecked(true);
		bilinearGroupBox->setEnabled(true); 
		break;
	}
   
}


////////////////////////////////////////////////////////////////
void materialDlg::trocarMaterial()
{
	linearGroupBox->setEnabled(false);    //material linear 
	bilinearGroupBox->setEnabled(false);    //material bilinear
	

	if(this->linearButton->isChecked())  
	{
		linearGroupBox->setEnabled(true);
		
		(*materialTipo) = LINEAR_ELASTIC;

		this->biModElast->setText("0.00");
		this->biPoisson->setText("0.00");
		this->biEscoamento->setText("0.00");
		this->biEncruamento->setText("0.00");

		//image.load(":/acmFrame/images/dialogos/restricao.png");   

        image.load(":/acmFrame/images/dialogos/linear_lk.png"); 
		this->graphicsView->setScene(new QGraphicsScene());
		this->graphicsView->scene()->addItem(new QGraphicsPixmapItem(image));


	} 
	else if(this->bilinearButton->isChecked())
	{
		bilinearGroupBox->setEnabled(true);
		
		(*materialTipo) = BI_LINEAR;

		
		this->linearModElast->setText("0.00");
		this->linearPoisson->setText("0.00");

		//image.load(":/acmFrame/images/dialogos/copia.png");   

        image.load(":/acmFrame/images/dialogos/bilinear_lk.png");
		this->graphicsView->setScene(new QGraphicsScene());
		this->graphicsView->scene()->addItem(new QGraphicsPixmapItem(image));


	}
	
}


////////////////////////////////////////////////////////////////

float materialDlg::getLinearModElast()
{
	return this->linearModElast->text().toFloat();  
}


void materialDlg::setLinearModElast(float *linearModElast) 
{	
	this->linearModElast_d = linearModElast;
	this->linearModElast->setText(QString::number(*linearModElast,'f',2));
   
}

////////////////////////////////////////////////////////////////

float materialDlg::getLinearPoisson()
{
	return this->linearPoisson->text().toFloat();  
}


void materialDlg::setLinearPoisson(float *linearPoisson) 
{	
	this->linearPoisson_d = linearPoisson;
	this->linearPoisson->setText(QString::number(*linearPoisson,'f',2));
   
}

////////////////////////////////////////////////////////////////
float materialDlg::getBiModElast()
{
	return this->biModElast->text().toFloat();  
}


void materialDlg::setBiModElast(float *biModElast) 
{	
	this->biModElast_d = biModElast;
	this->biModElast->setText(QString::number(*biModElast,'f',2));
   
}

////////////////////////////////////////////////////////////////

float materialDlg::getBiPoisson()
{
	return this->biPoisson->text().toFloat();  
}


void materialDlg::setBiPoisson(float *biPoisson) 
{	
	this->biPoisson_d = biPoisson;
	this->biPoisson->setText(QString::number(*biPoisson,'f',2));
   
}

////////////////////////////////////////////////////////////////

float materialDlg::getBiEscoamento()
{
	return this->biEscoamento->text().toFloat();  
}


void materialDlg::setBiEscoamento(float *biEscoamento) 
{	
	this->biEscoamento_d = biEscoamento;
	this->biEscoamento->setText(QString::number(*biEscoamento,'f',2));
   
}

////////////////////////////////////////////////////////////////

float materialDlg::getBiEncruamento()
{
	return this->biEncruamento->text().toFloat();  
}


void materialDlg::setBiEncruamento(float *biEncruamento) 
{	
	this->biEncruamento_d = biEncruamento;
	this->biEncruamento->setText(QString::number(*biEncruamento,'f',2));
   
}

